<template>
  <div class="app-container">

    <el-tabs v-model="activeName">
      <el-tab-pane label="预警列表" name="warn">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        </el-form>

        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="dockorList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            label="序号"
            type="index"
            width="50">
          </el-table-column>
          <el-table-column label="医院名称" align="center" prop="hospitalName">
            <template slot-scope="scope">
              <span v-if="scope.$index === 1">遵义市汇川区毛石镇中坝村中心卫生室</span>
              <span v-else-if="scope.$index === 2">遵义市汇川区毛石镇大梨村卫生室</span>
              <span v-else-if="scope.$index === 3">遵义市汇川区毛石镇乐遥村卫生室</span>
              <span v-else-if="scope.$index === 4">遵义市汇川区上海路街道新桥社区卫生室</span>
              <span v-else-if="scope.$index === 5">遵义市汇川区毛石镇卫生院</span>
              <span v-else-if="scope.$index === 6">汇川广庆医院</span>
              <span v-else-if="scope.$index === 7">遵义市汇川区董公寺街道烂田社区卫生室</span>
              <span v-else-if="scope.$index === 8">遵义市汇川区泗渡镇观坝社区中心卫生室</span>
              <span v-else-if="scope.$index === 9">遵义市汇川区高坪街道联丰村卫生室</span>
              <span v-else-if="scope.$index === 10">遵义市汇川区沙湾镇米粮村卫生室</span>
              <span v-else-if="scope.$index === 0">遵义市汇川区沙湾镇米粮村卫生室</span>
            </template>
          </el-table-column>
          <el-table-column label="注册号" align="center" prop="registerNumber" />
          <el-table-column label="许可证到期日期" align="center" prop="lincenseEnd" />
          <el-table-column label="辖区" align="center" prop="medicalAreaname" />
          <el-table-column label="预警日期" align="center" prop="warnTime" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <!--              <el-button-->
              <!--                size="mini"-->
              <!--                type="text"-->
              <!--               @click="dialogTableVisible = true"-->
              <!--              >查看</el-button>-->
              <el-popover
                placement="left-start"
                width="400"
                trigger="click">
                <h3>查看信息</h3>
                <ul>
                  <li>医院名称:
                    <span v-if="scope.$index === 1">遵义市汇川区毛石镇中坝村中心卫生室</span>
                    <span v-else-if="scope.$index === 2">遵义市汇川区毛石镇大梨村卫生室</span>
                    <span v-else-if="scope.$index === 3">遵义市汇川区毛石镇乐遥村卫生室</span>
                    <span v-else-if="scope.$index === 4">遵义市汇川区上海路街道新桥社区卫生室</span>
                    <span v-else-if="scope.$index === 5">遵义市汇川区毛石镇卫生院</span>
                    <span v-else-if="scope.$index === 6">汇川广庆医院</span>
                    <span v-else-if="scope.$index === 7">遵义市汇川区董公寺街道烂田社区卫生室</span>
                    <span v-else-if="scope.$index === 8">遵义市汇川区泗渡镇观坝社区中心卫生室</span>
                    <span v-else-if="scope.$index === 9">遵义市汇川区高坪街道联丰村卫生室</span>
                    <span v-else-if="scope.$index === 10">遵义市汇川区沙湾镇米粮村卫生室</span>
                    <span v-else-if="scope.$index === 0">遵义市汇川区沙湾镇米粮村卫生室</span>
                  </li>
                  <li>注册号: {{dockorList[scope.$index].registerNumber}}</li>
                  <li>许可证到期时间: {{dockorList[scope.$index].lincenseEnd}}</li>
                  <li>辖区: {{dockorList[scope.$index].medicalAreaname}}</li>
                  <li>预警日期: {{dockorList[scope.$index].warnTime}}</li>
                </ul>
                <el-button slot="reference" size="mini" type="text">查看</el-button>
              </el-popover>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <!-- 添加或修改【请填写功能名称】对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="审批机关名称" prop="organname">
              <el-input v-model="form.organname" placeholder="请输入审批机关名称" />
            </el-form-item>
            <el-form-item label="区划名称" prop="regionname">
              <el-input v-model="form.regionname" placeholder="请输入区划名称" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>

        <!--        <el-dialog title="查看信息" :visible.sync="dialogTableVisible">-->
        <!--          <li>医院名称: {{dockorList.hospitalName}}</li>-->
        <!--          <li>Spring Security</li>-->
        <!--          <li>JWT</li>-->
        <!--          <li>MyBatis</li>-->
        <!--          <li>Druid</li>-->
        <!--          <li>Fastjson</li>-->
        <!--          <li>...</li>-->
        <!--        </el-dialog>-->
      </el-tab-pane>
      <el-tab-pane label="处置列表" name="second"></el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import moment from 'moment';
import {listlicensedWarn} from "../../../api/his/warn";
export default {
  name: "Dockor",
  data() {
    return {

      activeName: 'warn',
      dialogTableVisible :false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      dockorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        clinicId: null,
        time: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList()
  },
  methods: {
    formattedTime(time) {
      return moment(time).format('YYYY-MM-DD'); // 这里的'time'为传递到组件的时间数据
    },
    generateRandomNumber() {
      // 生成一个 1 到 100 之间的随机数
      return Math.floor(Math.random() * 100) + 1;
    },


    /** 查询【请填写功能名称】列表 */
    getList() {
      const now = new Date()
      now.setDate(now.getDate() -1 )
      this.queryParams.time = this.formattedTime(now.toLocaleString());
      this.loading = true;
      listlicensedWarn(this.queryParams).then(response => {
        this.dockorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        hospitalName: null,
        medicalAreaname: null,
        minkeMedicalId: null,
        nextCheckDate: null,
        registerNumber: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log(this.queryParams.time)
      if(this.queryParams.time === null){
        this.$modal.msgError("请选择就诊日期");
        return
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDockor(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDockor(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDockor(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delDockor(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有【请填写功能名称】数据项？').then(() => {
        this.exportLoading = true;
        return exportDockor(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
